<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .red{
      background-color: red;
    }
    ul{
      display: flex;
      list-style: none;
    }
    li{
      margin: 10px;
    }
    .big{
      width: 100px;
      height: 100px;
      border-radius: 50%;
      border: 1px solid #000;
    }
  </style>
</head>

<body>
  <div id="app">

    <div :class="['big',item == index ? 'red' : '']"  v-for="item in 4">我是{{item}}个div</div>
    <div :class="{red:true}">我是一个div</div>
   <br>

   数组方法:
   <ul>
    <li @click="index = item" :class="[item == index ? 'red' : '']" v-for="item in 4" :key="item">
      我是第{{item}}个li
    </li>
   </ul>

   对象写法:
   <ul>
    <li @click="index = item" :class="{red:index == item}" v-for="item in 4" :key="item">
      我是第{{item}}个li
    </li>
   </ul>

   对象或者数组抽离写法:
   <ul>
    <li @click="index = item" :class="{red:index == item,...classaa}" v-for="item in 4" :key="item">
      我是第{{item}}个li
    </li>
   </ul>
   
  </div>
  <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.14/vue.min.js"></script>
  <script>
    var vm = new Vue({
      el: "#app",
      data: {
        msg: 'hello  vue',
        index:1,
        classaa:{big:true}
      },
      
    })

    // console.log(vm, 2222);
  </script>
</body>

</html>